# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: philefou <tuxication AT gmail DOT com>
# Contributor: lindquist <tomas@famolsen.dk>
# Contributor: Christoph Siegenthaler <csi@gmx.ch>
# Contributor: Mihai Militaru <mihai.militaru@ephemeros.org>
# Contributor: SpepS <dreamspepser at yahoo dot it>

pkgbase=glfw
pkgname=('glfw-x11' 'glfw-wayland' 'glfw-doc')
pkgver=3.3.8
pkgrel=1
arch=('loong64' 'x86_64')
url="https://www.glfw.org/"
license=('custom:ZLIB')
makedepends=('mesa' 'cmake' 'doxygen' 'vulkan-headers' 'vulkan-icd-loader'
             'extra-cmake-modules' 'wayland-protocols' 'libxi' 'libxrandr'
             'libxcursor' 'libxkbcommon' 'libxinerama')
source=("$pkgname-$pkgver.tar.gz::https://github.com/glfw/glfw/archive/${pkgver}.tar.gz")
sha512sums=('70d6d99fb7e7616990516070c9a430915dc68d89ec4fe785570f0b35f5c9606a34121e0cd57c0a7debb50e87e2a8e8d97d81a6d52d65ef454f7fd191bd9f679f')

prepare() {
  cd "$srcdir/$pkgbase-$pkgver"
  mkdir build-x11 build-wayland
}

build() {
  cd "$srcdir/$pkgbase-$pkgver/build-x11"

  cmake .. \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DCMAKE_INSTALL_LIBDIR=lib \
      -DBUILD_SHARED_LIBS=ON
  make docs

  cd ../build-wayland

  cmake .. \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DCMAKE_INSTALL_LIBDIR=lib \
      -DBUILD_SHARED_LIBS=ON \
      -DGLFW_USE_WAYLAND=ON
}

package_glfw-x11() {
  pkgdesc="A free, open source, portable framework for graphical application development (x11)"
  depends=('libxi' 'libxrandr' 'libxinerama' 'libxcursor' 'libgl')
  replaces=('glfw')
  conflicts=('glfw')
  provides=("glfw=$pkgver")

  cd "$srcdir/$pkgbase-$pkgver"/build-x11

  make DESTDIR=$pkgdir install

  cd ..
  install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"
}

package_glfw-wayland() {
  pkgdesc="A free, open source, portable framework for graphical application development (wayland)"
  depends=('wayland' 'libxkbcommon' 'libgl')
  conflicts=('glfw')
  provides=("glfw=$pkgver")

  cd "$srcdir/$pkgbase-$pkgver"/build-wayland

  make DESTDIR=$pkgdir install

  cd ..
  install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"
}

package_glfw-doc() {
  pkgdesc="Set of HTML documentation for GLFW"

  mkdir -p "${pkgdir}/usr/share/doc/glfw/"
  cp -r "${srcdir}/glfw-${pkgver}/build-x11/docs/html" "${pkgdir}/usr/share/doc/glfw"
}
